import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { RobFlagSignUpType } from "./data/RobFlagSignUpType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { PageItemRenderer } from "../../common/renderers/PageItemRenderer";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GameConst } from "../../../../component/gconst/GameConst";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { SecTimerButton } from "../../common/SecTimerButton";
import { SecTimerCountView } from "../../common/SecTimerCountView";
import { RobFlagShopCode } from "../../../../../GameConst/RobFlagShopCode";
import { _EPriceUnitRobFlagHonour } from "../../../../../EPrictUnit/_EPriceUnitRobFlagHonour";
type int = number;
//class RobFlagEnterWin
    
    export  class RobFlagEnterWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._bmpHonorIcon = new Object /* flash.display.Bitmap */();
            this._bmpHonorLabel = new Object /* flash.display.Bitmap */();
            this.setSize(344, 471);
            this.title = Language.getString(80511);
            this.titleHeight = 27;
            this._btnSingleSignUp.configEventListener(flash.events.MouseEvent.CLICK, this.clickSingleSignUpHandler);
            this._btnTeamSignUp.configEventListener(flash.events.MouseEvent.CLICK, this.clickTeamSignUpHandler);
            this._btnExchange.configEventListener(flash.events.MouseEvent.CLICK, this.clickExchangeHandler);
            this._btnLeave.configEventListener(flash.events.MouseEvent.CLICK, this.clickLeaveHandler);
            this._btnEnter.configEventListener(flash.events.MouseEvent.CLICK, this.clickEnterHandler);
            return;
        }

        public /* override */ dispose(arg1: Boolean=false): void
        {
            super.dispose(arg1);
            DisplayUtil.removeAndDisposeAllGUIComponent(this, arg1);
            return;
        }

        public updateExchangeList(arg1: DataProvider): void
        {
            this._listExchange.dataProvider = arg1;
            this._listExchange.drawNow();
            return;
        }

        public updateStateInLineTime(arg1: int, arg2: Boolean=false): void
        {
            this._timeSect.startCount(arg1);
            if (arg2 && this._timeSect.running) 
            {
                this._timeSect.stop();
            }
            return;
        }

        public updateMyHornor(arg1: int): void
        {
            this._txtMyHonor.htmlText = HTMLUtil.addColor(Language.getString(41637), GlobalStyle.color1) + HTMLUtil.addColor(arg1.toString(), GlobalStyle.color2);
            return;
        }

        public setCanCancel(arg1: Boolean): void
        {
            DisplayUtil.setEnabled(this._btnLeave, arg1);
            return;
        }

        public updateSignUpStatus(arg1: int): void
        {
            DisplayUtil.setEnabled(this._btnEnter, false);
            this._btnEnter.stop();
            this._btnEnter.reset();
            if (this._enterTimerId > 0) 
            {
                flash.utils.clearTimeout(this._enterTimerId);
                this._enterTimerId = 0;
            }
            var loc1=arg1;
            switch (loc1) 
            {
                case RobFlagSignUpType.single: case RobFlagSignUpType.team:
                {
                    DisplayUtil.setEnabled(this._btnLeave, true);
                    DisplayUtil.setEnabled(this._btnSingleSignUp, false);
                    DisplayUtil.setEnabled(this._btnTeamSignUp, false);
                    this.updateStateInLineTime(0);
                    break;
                }
                case RobFlagSignUpType.cancel:
                {
                    DisplayUtil.setEnabled(this._btnLeave, false);
                    DisplayUtil.setEnabled(this._btnSingleSignUp, true);
                    DisplayUtil.setEnabled(this._btnTeamSignUp, true);
                    this.updateStateInLineTime(0, true);
                    break;
                }
                case RobFlagSignUpType.initSingle:
                {
                    DisplayUtil.setEnabled(this._btnLeave, false);
                    DisplayUtil.setEnabled(this._btnSingleSignUp, true);
                    DisplayUtil.setEnabled(this._btnTeamSignUp, false);
                    this.updateStateInLineTime(0, true);
                    break;
                }
                case RobFlagSignUpType.initTeam:
                {
                    DisplayUtil.setEnabled(this._btnLeave, false);
                    DisplayUtil.setEnabled(this._btnSingleSignUp, false);
                    DisplayUtil.setEnabled(this._btnTeamSignUp, true);
                    this.updateStateInLineTime(0, true);
                    break;
                }
                case RobFlagSignUpType.matchSuccess:
                {
                    DisplayUtil.setEnabled(this._btnLeave, false);
                    DisplayUtil.setEnabled(this._btnSingleSignUp, false);
                    DisplayUtil.setEnabled(this._btnTeamSignUp, false);
                    DisplayUtil.setEnabled(this._btnEnter, true);
                    this._btnEnter.startCountdown(30);
                    this.updateStateInLineTime(0, true);
                    break;
                }
            }
            return;
        }

        /* internal  */on30SecondsNoEnter(): void
        {
            if (this._enterTimerId > 0) 
            {
                this._enterTimerId = 0;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobFlagUserEnterCopyTimeOut));
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 37, 313, 150, this);
            var loc1=GlobalStyle.textFormat1;
            loc1.leading = 4;
            var loc2=ObjCreate.createGTextField("", 24, 43, 293, 150, this, loc1);
            loc2.multiline = true;
            loc2.wordWrap = true;
            loc2.htmlText = Language.getString(80512);
            ObjCreate.createBg(17, 190, 313, 271, this);
            ObjCreate.createBitmap(ImagesConst.PackItemBg, 29, 198, this);
            ObjCreate.setObjAttri(this._bmpHonorIcon, 33, 201, -1, -1, this);
            ObjCreate.setObjAttri(this._bmpHonorLabel, 75, 198, -1, -1, this);
            this._txtMyHonor = ObjCreate.createGTextField("", 73, 219, 200, 20, this);
            this.updateMyHornor(0);
            ObjCreate.createBitmap(ImagesConst.Fire, 28, 232, this);
            var loc3=ObjCreate.createGTextField("", 49, 242, 240, 20, this, GlobalStyle.textFormatGreen);
            loc3.htmlText = Language.getString(80535);
            this._listExchange = ObjCreate.createTileList(29, 260, 285, 90, this);
            this._listExchange.columnWidth = 41;
            this._listExchange.rowHeight = 41;
            this._listExchange.setStyle("cellRenderer", PageItemRenderer);
            ObjCreate.createBg(29, 347, 283, 1, this, ImagesConst.SplitLine);
            this._btnSingleSignUp = ObjCreate.createGButton(Language.getString(80513), 41, 365, 65, 23, this);
            this._btnTeamSignUp = ObjCreate.createGButton(Language.getString(80514), 141, 365, 65, 23, this);
            this._btnEnter = ObjCreate.createSecTimerButton(Language.getString(41847), 241, 365, 65, 23, this);
            this._btnEnter.timeOutHandler = this.on30SecondsNoEnter;
            this._timeSect = ObjCreate.createSecTimeCountView(Language.getString(80515), 25, 396, 250, 20, this);
            this._timeSect.startCount(0);
            this._timeSect.stop();
            ObjCreate.createBg(29, 421, 283, 1, this, ImagesConst.SplitLine);
            this._btnExchange = ObjCreate.createGButton(Language.getString(80516), 41, 430, 83, 23, this);
            this._btnLeave = ObjCreate.createGButton(Language.getString(80527), 205, 430, 83, 23, this);
            LoaderHelp.addResCallBack(ResFileConst.RobFlag, this.resGotHandler);
            return;
        }

        /* internal  */resGotHandler(): void
        {
            this._bmpHonorIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.RobFlag_HonorIcon);
            this._bmpHonorLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.RobFlag_Score);
            return;
        }

        /* internal  */clickSingleSignUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobFlagSingleSignUpReq));
            return;
        }

        /* internal  */clickTeamSignUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobFlagTeamSignUpReq));
            return;
        }

        /* internal  */clickExchangeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1={"shopCode": RobFlagShopCode, "type": _EPriceUnitRobFlagHonour};
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopOpenHonor, loc1));
            return;
        }

        /* internal  */clickLeaveHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobFlagSignUpLeaveReq));
            return;
        }

        /* internal  */clickEnterHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RobFlagEnterCopyReq));
            return;
        }

        /* internal */ /* var */_bmpHonorIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpHonorLabel: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtMyHonor: GTextFiled;

        /* internal */ /* var */_listExchange: GTileList;

        /* internal */ /* var */_btnSingleSignUp: GButton;

        /* internal */ /* var */_btnTeamSignUp: GButton;

        /* internal */ /* var */_btnEnter: SecTimerButton;

        /* internal */ /* var */_timeSect: SecTimerCountView;

        /* internal */ /* var */_btnExchange: GButton;

        /* internal */ /* var */_btnLeave: GButton;

        /* internal */ /* var */_enterTimerId: int=0;
    }
